package com.p2l.letterblocks;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class DialogItem extends Dialog {
	public static final int WARDROBE = 0;
	public static final int SHOP = 1;
	
	private ListView list;
	private Context context;
	
	private int mode;
	
	private OnItemClickListener listener = new OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			if (mode == WARDROBE) {
				ActivityWardrobe wardrobe = (ActivityWardrobe) context;
				wardrobe.onItemGroupChanged(position);
			} else if (mode == SHOP) {
				ActivityShop shop = (ActivityShop) context;
				shop.onItemGroupChanged(position);
			}
			dismiss();
		}
	};
	
	public DialogItem(Context context, int n) {
		super(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
		setContentView(R.layout.dialog_item);

		mode = n;
		this.context = context;

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.spinner, context.getResources().getStringArray((mode == SHOP ? R.array.shop : R.array.groups)));
		list = (ListView) findViewById(R.id.lstItem);
		list.setAdapter(adapter);
		list.setOnItemClickListener(listener);
	}
}